import React, {useState} from 'react';
import {Form, Input, Button, message} from "antd";
import { LockOutlined, UserOutlined } from '@ant-design/icons';
import styles from './index.module.less'
import {useNavigate} from "react-router-dom";
import {useAppDispatch} from '@/hooks'
import {postLoginAsync1} from "@/store/slice/auth";
function Login() {
    const navigate = useNavigate();
    const dispatch = useAppDispatch();
    const [isLoading, setIsLoading] = useState<boolean>(false)
    const submitHandler = async (values:any) => {
        setIsLoading(true);
        try {
            const result:any =await dispatch(postLoginAsync1(values));
            console.log(result,"+++result")
            message.success(result.message);
            navigate("/");

        } catch (error) {
            setIsLoading(false);
            console.log(error)
        }


    }
    return (
        <div className={styles.login}>
            <div>
                <h1>尚医通管理系统</h1>
                <Form
                    name="normal_login"
                    className="login-form"
                    initialValues={{ remember: true }}
                    onFinish={submitHandler}
                >
                    <Form.Item
                        name="username"
                        rules={[{ required: true, message: '请输入管理员账号!' }]}
                    >
                        <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="请输入管理员账号" />
                    </Form.Item>
                    <Form.Item
                        name="password"
                        rules={[{ required: true, message: '请输入管理员密码!' }]}
                    >
                        <Input
                            prefix={<LockOutlined className="site-form-item-icon" />}
                            type="password"
                            placeholder="请输入管理员密码"
                        />
                    </Form.Item>

                    <Form.Item>
                        <Button loading={isLoading} type="primary" htmlType="submit" className="login-form-button">
                            登录
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        </div>
    );
}

export default Login;